package viqiang.ye.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Component;
import viqiang.ye.HelloService;

/**
 * 指定要发布服务的接口
 * weight 指定暴露服务的权重
 */
@Service(interfaceClass = HelloService.class, loadbalance = RoundRobinLoadBalance.NAME,
 weight = 110)
@Component
public class HelloServiceImpl implements HelloService {

    /**
     * 注意： 降级方法的方法参数和返回类型必须和原方法保持一致
     * @param message
     * @return
     */
    @HystrixCommand(fallbackMethod = "defaultHello")
    @Override
    public String hello(String message) {
        System.out.println("调用 viqiang.ye.service.HelloServiceImpl#hello");
        String a = null;
        a.toString();
        return "hello," + message;
    }

    public String defaultHello(String message) {
        return "hello anonymous";
    }
}
